package com.library.workbench.service.impl;

import com.library.workbench.mapper.BorrowMapper;
import com.library.workbench.pojo.Book;
import com.library.workbench.pojo.Borrow;
import com.library.workbench.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("borrowService")
public class BorrowServiceImpl implements BorrowService {
    @Autowired
    private BorrowMapper borrowMapper;

    @Override
    public List<Borrow> queryBorrowByUserId(String userId) {
        return borrowMapper.selectBorrowByUserId(userId);
    }

    @Override
    public List<Book> queryExistBookForConditionForPage(Map<String, Object> map) {
        return borrowMapper.queryBooksByNameOrAuthorOrActForPage(map);
    }

    @Override
    public int queryExistBookByConditionForRows(Map<String, Object> map) {
        return borrowMapper.queryBooksByNameOrAuthorOrActForRows(map);
    }

    @Override
    public int saveBorrow(Borrow borrow) {
        return borrowMapper.insertBorrowInfoByBookIdUserId(borrow);
    }

    @Override
    public List<Borrow> queryBorrowInfoByUserIdAndNotReturn(String userId) {
        return borrowMapper.queryRequiredReturnBookBorrowInfoByUserId(userId);
    }

    @Override
    public int saveReturnBorrowInfo(Borrow borrow) {
        return borrowMapper.returnBorrowById(borrow);
    }

    @Override
    public Borrow queryBorrowById(String borrowId) {
        return borrowMapper.selectBorrowById(borrowId);
    }

    @Override
    public List<Borrow> queryBorrowInfoByConditionForPage(Map<String, Object> map) {
        return borrowMapper.queryBorrowInfoByConditionForPage(map);
    }

    @Override
    public int queryBorrowInfoByConditionForRows(Map<String, Object> map) {
        return borrowMapper.queryBorrowInfoByConditionForRows(map);
    }

    @Override
    public List<Borrow> queryNeedReturnBorrowByConditionForPage(Map<String, Object> map) {
        return borrowMapper.queryRequiredReturnBookBorrowInfoByUserIdBookNameBookActAuthorForPage(map);
    }

    @Override
    public int queryNeedReturnBorrowByConditionForRows(Map<String, Object> map) {
        return borrowMapper.queryRequiredReturnBookBorrowInfoByUserIdBookNameBookActAuthorForRows(map);
    }
}
